package classes.view
{
	import classes.OX_Application;
	import classes.controller.DAOSendFlash;
	import classes.controller.EClick;
	import classes.controller.EDataObject;
	import classes.view.component.WaitingRoom;
	
	import flash.events.Event;
	import flash.external.ExternalInterface;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class Mediator_Waitingroom extends Mediator implements IMediator
	{
		public static const NAME:String = "Mediator_Waitingroom";
		public function Mediator_Waitingroom(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			init();
		}
		
		override public function listNotificationInterests():Array
		{
			return [OX_Application.WAITING_ROOM_IN,
					OX_Application.CLICK_EVENT,
					OX_Application.WAITING_ROOM_CREATE
					];
		}
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName()){
				case OX_Application.WAITING_ROOM_IN :
					sendNotification(OX_Application.LOADING_IN);
					waitingRoom.waitingroom_switch = true;
					break;
				case OX_Application.CLICK_EVENT :
						if(notification.getBody() == "go"){
							//바로가기로 실행.
							waitingRoom.waitingroom_switch = true;
						}
						else if(notification.getBody() == "scoreOff")
						{
							waitingRoom.waitingroom_switch = true;
						}
					break;
				case OX_Application.WAITING_ROOM_CREATE :
					waitingRoom.waitingroom_switch = true;
					
					break;
			}
		}
		
		private function init():void
		{
			waitingRoom.addEventListener(EClick.EVENT_CLICK,				onClickEvent);
			waitingRoom.addEventListener(EDataObject.EVENT_DATAOBJECT,		personalInfoPopup);
			waitingRoom.addEventListener("loadingOff",						loadingOffSend);
		}
		
		private function onClickEvent(e:EClick):void
		{
			switch(e._click){
				case "start" :
					sendNotification(OX_Application.GAME_START);
					break;
				case "settingroom" :
					sendNotification(OX_Application.UTIL_CLICK_EVENT, 'gameSetting');
					break;
				case "outroom" :
					sendNotification(OX_Application.LOADING_IN);
					sendNotification(OX_Application.LIST_ROOM_ON);
					break;
			}
		}
		
		private function personalInfoPopup(e:EDataObject):void
		{
			sendNotification(OX_Application.WAITING_PERSONAL_INFO, e._object);
		}
		private function loadingOffSend(e:Event):void{sendNotification(OX_Application.LOADING_OUT);}
		
		
		protected function get waitingRoom():WaitingRoom
		{
			return viewComponent as WaitingRoom;
		}
	}
}